package Com.Hupochuan.Dal.Tab;

import java.util.Hashtable;

import Com.Hupochuan.Dal.DBManager.DBManager;
import Com.Hupochuan.Vo.PageMovie;

public class PageMovieTab {
	/*
	 * 本类私有对象
	 */
	private DBManager<PageMovie> dbManager = new DBManager<PageMovie>(PageMovie.class);
	
	/*
	 * 单一实例
	 */
	private PageMovieTab(){}
	private static PageMovieTab pageMovieTab = new PageMovieTab();
	public static PageMovieTab getObject(){
		return pageMovieTab;
	}
	
	/*
	 * 添加数据
	 */
	public int appendData(long movieId){
		//参数部分
		StringBuffer sqlBuff = new StringBuffer();
		Hashtable<String,Object> paraHash = new Hashtable<String,Object>();
		
		//sql语句部分
		sqlBuff.append(" insert into PageMovie set ");
		sqlBuff.append(" 	movieId=${movieId}, ");
		sqlBuff.append(" 	createTime=now(), ");
		sqlBuff.append(" 	updateTime=now() ");
		
		//sql参数部分
		paraHash.put("movieId",movieId);
		
		//执行sql 并返回参数
		return dbManager.updateSql(sqlBuff.toString(),paraHash);
	}
	
	/*
	 * 根据电影ID 更新数据
	 */
	public int updateData(String url,long movieId){
		//参数部分
		StringBuffer sqlBuff = new StringBuffer();
		Hashtable<String,Object> paraHash = new Hashtable<String,Object>();
		
		//sql语句部分
		sqlBuff.append(" update PageMovie set ");
		sqlBuff.append(" url=${url}, ");
		sqlBuff.append(" isUpdate=0, ");
		sqlBuff.append(" updateTime=now() ");
		sqlBuff.append(" where movieId=${movieId} ");
		
		//sql参数部分
		paraHash.put("url",url);
		paraHash.put("movieId",movieId);
		
		//执行sql 并返回参数
		return dbManager.updateSql(sqlBuff.toString(),paraHash);
	}
	
	/*
	 * 获得页面电影对象
	 */
	public PageMovie findPageMovie(long movieId){
		//参数部分
		PageMovie pageMovie = null;
		StringBuffer sqlBuff = new StringBuffer();
		Hashtable<String,Object> paraHash = new Hashtable<String,Object>();
		
		//sql语句部分
		sqlBuff.append(" select * from PageMovie where movieId=${movieId} ");
		
		//sql参数部分
		paraHash.put("movieId",movieId);
		
		//从列表中获得对象
		pageMovie = dbManager.querySqlReturnVo(sqlBuff.toString(),paraHash);
		
		//返回
		return pageMovie;
	}
}
